package com.wlyuan.open.scanner.domain.consignee;

import com.wlyuan.open.scanner.dao.entity.EndUserDO;
import com.wlyuan.open.scanner.utils.JsonUtils;
import com.wlyuan.open.scanner.utils.mappings.BaseMapping;
import com.wlyuan.open.scanner.utils.mappings.MappingInvalid;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author lijing
 * @description
 */
public class ConsigneeConvert {

    private static final Convert CONVERT = Mappers.getMapper(Convert.class);

    @Mapper(uses = MappingInvalid.class)
    public interface Convert {

        @Mappings({
                @Mapping(target = "id", source = "enduserId"),
                @Mapping(target = "contactMobile", source = "enduserPhone"),
                @Mapping(target = "contactName", source = "enduserContact"),
                @Mapping(target = "name", source = "enduserName"),
                @Mapping(target = "contactEmail", source = "enduserMail"),
                @Mapping(target = "industry", source = "enduserIndustry"),
                @Mapping(target = "abbr", source = "enduserShortname"),
                @Mapping(target = "url", source = "enduserWeb"),
                @Mapping(target = "englishName", source = "enduserEnname"),
                @Mapping(target = "englishAbbr", source = "enduserShortenname"),
                @Mapping(target = "logo", source = "enduserLogo"),
                @Mapping(target = "fax", source = "enduserFax"),
                @Mapping(target = "zipcode", source = "enduserZip"),
                @Mapping(target = "profile", source = "enduserComments"),
                @Mapping(target = "address", source = "enduserAddress"),
                @Mapping(target = "bankName", source = "enduserBank"),
                @Mapping(target = "bankAccount", source = "enduserBankaccount"),
                @Mapping(target = "corporation", source = "enduserMaster"),
                @Mapping(target = "businessLicenseUrl", source = "enduserLicense"),
                @Mapping(target = "wechatOfficialNo", source = "enduserWeixin"),
                @Mapping(target = "customerId", source = "enduserCustomerid"),

                @Mapping(target = "tenantId", source = "enduserOwnercompany"),
                @Mapping(target = "sourceKey", source = "enduserId"),
                @Mapping(target = "createTime", source = "enduserInserttime"),
                @Mapping(target = "updateTime", source = "enduserUpdatetime"),
                @Mapping(target = "createBy", source = "enduserCreator"),
                @Mapping(target = "updateBy", source = "enduserUpdater"),

                @Mapping(target = "consigneeConfig.deliveryTime", source = "deliveryTime"),
                @Mapping(target = "consigneeConfig.certPushSwitch", source = "enduserSendcertificatestatus"),
        })
        @BaseMapping
        Consignee convert(EndUserDO endUserDO);

        @AfterMapping
        default void after(@MappingTarget Consignee target, EndUserDO source) {
            target.setRaw(JsonUtils.withNullJson(source));
        }

        /**
         * 转换
         *
         * @param source
         * @return
         */
        List<Consignee> convert(List<EndUserDO> source);

    }

    public static List<Consignee> convert(List<EndUserDO> creation) {
        return CONVERT.convert(creation);
    }

    public static Consignee convert(EndUserDO creation) {
        return CONVERT.convert(creation);
    }
}
